#!/bin/bash
## in this example I use vlan 2001-2004, which are hex equivalents of 0x07D1 -0x07D4

# internet facing interface
INET=eth2
# downlink facing interface
DOWN=eth3

### configuring download rules:
tc qdisc del dev $DOWN root
tc qdisc replace dev $DOWN root handle 1: htb
tc class replace dev $DOWN parent 1: classid 1:2001 htb rate 11mbit
tc class replace dev $DOWN parent 1: classid 1:2002 htb rate 21mbit
tc class replace dev $DOWN parent 1: classid 1:2003 htb rate 31mbit
tc class replace dev $DOWN parent 1: classid 1:2004 htb rate 41mbit
tc filter replace dev $DOWN protocol all parent 1: prio 100 basic match "meta(vlan mask 0xfff eq 0x07D1)" flowid 1:2001
tc filter replace dev $DOWN protocol all parent 1: prio 100 basic match "meta(vlan mask 0xfff eq 0x07D2)" flowid 1:2002
tc filter replace dev $DOWN protocol all parent 1: prio 100 basic match "meta(vlan mask 0xfff eq 0x07D3)" flowid 1:2003
tc filter replace dev $DOWN protocol all parent 1: prio 100 basic match "meta(vlan mask 0xfff eq 0x07D4)" flowid 1:2004

printf "########## Printout for DOWNLOAD: ###################\n"
printf "\n"
printf "$(tc filter show dev $DOWN)\n"
printf "$(tc class show dev $DOWN)\n"
printf "$(tc qdisc show dev $DOWN)\n"
printf "\n"

### configuring upload rules:
tc qdisc del dev $INET root
tc qdisc replace dev $INET root handle 2: htb
tc class replace dev $INET parent 2: classid 2:2001 htb rate 11mbit
tc class replace dev $INET parent 2: classid 2:2002 htb rate 21mbit
tc class replace dev $INET parent 2: classid 2:2003 htb rate 31mbit
tc class replace dev $INET parent 2: classid 2:2004 htb rate 41mbit
tc filter replace dev $INET protocol all parent 2: prio 100 basic match "meta(vlan mask 0xfff eq 0x07D1)" flowid 2:2001
tc filter replace dev $INET protocol all parent 2: prio 100 basic match "meta(vlan mask 0xfff eq 0x07D2)" flowid 2:2002
tc filter replace dev $INET protocol all parent 2: prio 100 basic match "meta(vlan mask 0xfff eq 0x07D3)" flowid 2:2003
tc filter replace dev $INET protocol all parent 2: prio 100 basic match "meta(vlan mask 0xfff eq 0x07D4)" flowid 2:2004

printf "########## Printout for UPLOAD: #####################\n"
printf "\n"
printf "$(tc filter show dev $INET)\n"
printf "$(tc class show dev $INET)\n"
printf "$(tc qdisc show dev $INET)\n"
printf "\n"

exit 0
